<?php

/**
 * Trida entity pro uzivatele.
 *
 * @author David Dusek
 */
namespace CMS\User\Models;

use Doctrine\ORM\Mapping as ORM;

/** 
 * @ORM\Entity(repositoryClass="\CMS\User\Models\UserRepository")
 * @ORM\Table(name="user")
 */
class User extends \Nette\Object {    
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     * @var int 
     */
    private $id;
    
    /**
     * @ORM\Column(name="`name`", length=45)
     * @var string 
     */
    private $name;
    
    /**
     * @ORM\Column(length=45)
     * @var string 
     */
    private $surname;
    
    /**
     * @ORM\Column(name="degree_before", length=40)
     * @var string 
     */
    private $degreeBefore;
    
    /**
     * @ORM\Column(name="degree_after", length=40)
     * @var string 
     */
    private $degreeAfter;
    
    
    /**
     * @ORM\Column(length=45)
     * @var string 
     */
    private $username;    
    
    /**
     * @ORM\Column(length=40)
     * @var string 
     */
    private $password;
    
    /**
     * @ORM\Column(length=2)
     * @var string 
     */
    private $language;
    
    /**
     * @ORM\Column(type="boolean")
     * @var boolean 
     */
    private $deleted = 0;
    
    /**
     * @ORM\manyToOne(targetEntity="\CMS\User\Models\Group", inversedBy="users")
     * @ORM\joinColumn(name="group_id", referencedColumnName="id")
     */
    private $group;
    
    /**
     * @ORM\OneToMany(targetEntity="\CMS\User\Models\UserLog", mappedBy="`user`")
     */
    private $logRecords;
    
    public function __construct()
    {
        $this->logRecords = new \Doctrine\Common\Collections\ArrayCollection();        
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function setName($name) {
        $this->name = $name; 
    }

    public function getName() {
        return $this->name;
    }

    public function setSurname($surname) {
        $this->surname = $surname; 
    }

    public function getSurname() {
        return $this->surname;
    }
    
    public function setDegreeBefore($degreeBefore) {
        $this->degreeBefore = $degreeBefore; 
    }

    public function getDegreeBefore() {
        return $this->degreeBefore;
    }
    
    public function setDegreeAfter($degreeAfter) {
        $this->degreeAfter = $degreeAfter; 
    }

    public function getDegreeAfter() {
        return $this->degreeAfter;
    }

    
    public function setUsername($username) {
        $this->username = $username; 
    }

    public function getUsername() {
        return $this->username;
    }

    public function setPassword($password) {
        $this->password = $password; 
    }

    public function getPassword() {
        return $this->password;
    }
    
    public function setLanguage($language) {
        $this->language = $language; 
    }

    public function getLanguage() {
        return $this->language;
    }
    
    public function setDeleted($deleted) {
        $this->deleted = $deleted; 
    }

    public function getDeleted() {
        return $this->deleted;
    }
    
    public function setGroup(Group $group) {
        $this->group = $group;
    }
    
    public function getGroup() {
        return $this->group;
    }
    
    /* LogRecords */
    public function addLogRecord(UserLog $log) {
        $this->logRecords->add($log);
        $log->setUser($this);
    }
    
    public function removeLogRecord(UserLog $log) {
        $this->logRecords->removeElement($log);
        $log->setUser(NULL);
    }
    
    public function getLogRecords() {
        return $this->logRecords;
    }
}
